# Maintainer: Bruno Pagani <archange@archlinux.org>
# Maintainer: Muflone http://www.muflone.com/contacts/english/
# Contributor: Chris Warrick <aur@chriswarrick.com>

_pkg=cloudpickle
pkgname=python-${_pkg}
pkgver=2.2.1
pkgrel=2
pkgdesc="Extended pickling support for Python objects"
arch=(any)
url="https://github.com/cloudpipe/cloudpickle"
license=(BSD)
depends=(python)
makedepends=(
    python-build
    python-installer
    python-setuptools
    python-wheel
)
checkdepends=(
    python-pytest
    python-psutil
    python-tornado
    python-numpy
)
options=(!emptydirs)
source=(https://files.pythonhosted.org/packages/source/${_pkg::1}/${_pkg}/${_pkg}-${pkgver}.tar.gz)
sha256sums=('d89684b8de9e34a2a43b3460fbca07d09d6e25ce858df4d5a44240403b6178f5')

build() {
  cd ${_pkg}-${pkgver}
  python -m build --wheel --no-isolation
}

check() {
  cd ${_pkg}-${pkgver}
  cd tests/cloudpickle_testpkg
  python setup.py build
  cd ../../
  # file_handles: https://github.com/cloudpipe/cloudpickle/issues/252
  # builtin_classmethod: https://github.com/cloudpipe/cloudpickle/pull/486
  # pytest_module: https://github.com/cloudpipe/cloudpickle/issues/487
  PYTHONPATH="${PWD}"/tests/cloudpickle_testpkg/build/lib/ \
  pytest -vl --color=yes -m 'not avoid_ci' \
    --deselect tests/cloudpickle_test.py::CloudPickleTest::test_builtin_classmethod \
    --deselect tests/cloudpickle_test.py::CloudPickleTest::test_dynamic_pytest_module \
    --deselect tests/cloudpickle_test.py::Protocol2CloudPickleTest::test_builtin_classmethod \
    --deselect tests/cloudpickle_test.py::Protocol2CloudPickleTest::test_dynamic_pytest_module \
    --deselect tests/cloudpickle_file_test.py::CloudPickleFileTests::test_pickling_special_file_handles \
    --deselect tests/cloudpickle_test.py::CloudPickleTest::test_pickling_file_handles \
    --deselect tests/cloudpickle_test.py::Protocol2CloudPickleTest::test_pickling_file_handles

}

package() {
  cd ${_pkg}-${pkgver}
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
